package nl.boektrust.btsoep.client;

import java.util.HashSet;

import nl.boektrust.btsoep.shared.model.Person;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class StoredPersonsPanel extends VerticalPanel {
	private Btsoep btsoep;
	
	
	/**
	 * @return the btsoep
	 */
	public Btsoep getBtsoep() {
		return btsoep;
	}


	/**
	 * @param btsoep the btsoep to set
	 */
	public void setBtsoep(Btsoep btsoep) {
		this.btsoep = btsoep;
	}


	public void refresh() {
		HashSet<Person> personList = this.getBtsoep().getStoredPersonsList();
		for (int i = this.getWidgetCount()-1; i>=0; i--) this.remove(i);
		if (personList != null) {
			if (personList.size() > 0) {
				this.add(new HTML("<h3>Mensen</h3>"));
				Button deleteAllButton = new Button("Verwijder");
				deleteAllButton.addClickHandler(new ClickHandler() {
					public void onClick(ClickEvent event) {
						System.out.print("CLICK");
						btsoep.getStoredPersonsList().clear();
						refresh();
						
					}
					
				});
				this.add(deleteAllButton);
				
				
				for (Person person : personList) {
					this.add(new Label(person.getName()));
				}
			} else {
			}
		}
	}
	public StoredPersonsPanel(Btsoep btsoep) {
		this.btsoep = btsoep;
		this.refresh();
	}

}
